package com.qfedu.openplateform.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.qfedu.openplateform.manager.dao.CustomerMapper;
import com.qfedu.openplateform.manager.entity.Customer;
import com.qfedu.openplateform.manager.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public List<Customer> getAllCustomer(Customer customer, int page, int limit) {
        PageHelper.startPage(page, limit);
        List<Customer> customerList = customerMapper.getAllCustomer(customer);
        return customerList;
    }

    @Override
    public List<Customer> getAllCustomer() {
        return customerMapper.getAllCustomer(null);
    }

    @Override
    public Customer getCustomerById(int id) {
        return customerMapper.getCustomerById(id);
    }

    @Override
    public int addCustomer(Customer customer) {
        return customerMapper.addCustomer(customer);
    }

    @Override
    public int updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer);
    }

    @Override
    public void deleteCustomer(int[] ids) {
        for (int id : ids) {
            Customer customer = customerMapper.getCustomerById(id);
            if (customer != null) {
                customer.setState(0);
                customerMapper.updateCustomer(customer);
            }
        }
    }

}
